package com.media.system.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * MinIO对象存储配置
 * 
 * @author Claude
 * @since 2024-01-20
 */
@Configuration
public class MinioConfig {

    @Bean
    public MinioClient minioClient(MinioProperties minioProperties) {
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }

    @Data
    @Component
    @ConfigurationProperties(prefix = "minio")
    public static class MinioProperties {
        
        /**
         * MinIO服务地址
         */
        private String endpoint = "http://localhost:9000";
        
        /**
         * 访问密钥
         */
        private String accessKey = "minioadmin";
        
        /**
         * 秘密密钥
         */
        private String secretKey = "minioadmin";
        
        /**
         * 默认存储桶名称
         */
        private String bucketName = "media-files";
        
        /**
         * 访问URL前缀
         */
        private String urlPrefix = "http://localhost:9000";
        
        /**
         * 是否启用MinIO
         */
        private boolean enabled = true;
    }
}